import 'package:environmental_les_app/common/style/colours.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';
import 'package:flutter_clx_base/widget/clx_web_widget.dart';

import 'index.dart';
import 'widgets/my_willpopscope.dart';

class WebPage extends GetView<WebController> {
  const WebPage({super.key});

  // 主视图
  Widget _buildView() {
    return Stack(
      children: [
        WebViewWidget(
          controller: controller.webViewController,
        ),
        Offstage(
          offstage: controller.loadPercentage >= 1,
          child: GFProgressBar(
            percentage: controller.loadPercentage,
            backgroundColor: Colors.blueGrey,
            progressBarColor: Colours.appMain,
            margin: EdgeInsets.zero,
          ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<WebController>(
      init: WebController(),
      id: "web",
      builder: (_) {
        return MyWillPopScope(
          onWillPop: (didPop) {
            controller.onBack();
          },
          child: Scaffold(
            body: _buildView(),
          ),
        );
      },
    );
  }
}
